import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginLess } from '@rsbuild/plugin-less';
import theme from '@ant-design/antd-theme-variable';
import respackConfig from './rspack.config'
const ReactCompilerConfig = {
  target: '19',
  /* ... */
};
export default defineConfig({
  html: {
    title({ entryName }) {
      const titles = {
        foo: 'Foo Page',
        bar: 'Bar Page',
      };
      return titles[entryName] || 'ERP';
    },
  },

  server: {
    proxy: {
      '/api/lms': {
        target: 'http://localhost:6068',
        changeOrigin: true,
      },
      '/api/lms/ws': {
        target: 'ws://localhost:6068',
        changeOrigin: true,
        ws: true,
      },
    },
  },
  plugins: [
    pluginReact({
      swcReactOptions: {
        runtime: 'automatic',
        importSource: '@emotion/react',
      },
    }),
    pluginLess({
      lessLoaderOptions: {
        lessOptions: {
          modifyVars: {
            '@ant-prefix': 'ant',
            ...theme,
            '@s-site-menu-width': '258px',
            '@root-entry-name': 'variable',
            '@border-radius-base': '4px',
            '@primary-color': '#1677FF',
            '@error-color': '#ff4d4',
            '@info-color': '#52c41a',
            '@warning-color': '#faad14',
          },
          javascriptEnabled: true,
        },
      },
    }),

    pluginBabel({
      include: /\.(?:jsx|tsx)$/,
      babelLoaderOptions(opts) {
        opts.plugins?.unshift([
          'babel-plugin-react-compiler',
          ReactCompilerConfig,
        ]);
      },
    }),
  ],
  tools: {
    swc: {
      jsc: {
        experimental: {
          plugins: [['@swc/plugin-emotion', {}]],
        },
      },
    },
    rspack: respackConfig,
  },
});
